package com.pureut.system.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.system.domain.SysShopModeling;
import com.pureut.system.domain.vo.SysShopModelingVo;
import com.pureut.system.service.ISysShopModelingService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 车间建模控制层
 * @Param ShopModeling
 * @Date 22-12-23
 * @Author hl
 **/
@RestController
@RequestMapping("/modeling")
public class SysShopModelingController extends BaseController {

    @Resource
    private ISysShopModelingService sysShopModelingService;

    /**
     * 获取车间建模
     */
    @RequiresPermissions("system:shopAdministration:modelings:modeling:list")
    @GetMapping("/list")
    public TableDataInfo list(SysShopModelingVo sysShopModeling) {
        startPage();
        List<SysShopModeling> list = sysShopModelingService.selectShopModelingList(sysShopModeling);
        return getDataTable(list);
    }

    /**
     * 新增车间建模
     */
    @RequiresPermissions("system:shopAdministration:modelings:modeling:add")
    @Log(title = "新增车间建模", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysShopModeling sysShopModeling) throws Exception {
        return toAjax(sysShopModelingService.insertShopModeling(sysShopModeling));
    }

    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("system:shopAdministration:modelings:modeling:query")
    @GetMapping(value = "/{modelingId}")
    public AjaxResult getModelingInfo(@PathVariable long modelingId) {
        return AjaxResult.success(sysShopModelingService.selectModelingById(modelingId));
    }

    /**
     * 修改车间建模
     */
    @RequiresPermissions("system:shopAdministration:modelings:modeling:edit")
    @Log(title = "车间建模", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SysShopModeling sysShopModeling) throws Exception {
        return toAjax(sysShopModelingService.updateShopModelingEdit(sysShopModeling));
    }

    /**
     * 批量删除车间建模
     */
    @RequiresPermissions("system:shopAdministration:modelings:modeling:remove")
    @Log(title = "车间建模", businessType = BusinessType.DELETE)
    @DeleteMapping("/{modelingId}")
    public AjaxResult remove(@PathVariable("modelingId") String modelingId) throws Exception {
        return sysShopModelingService.deleteModelingById(modelingId);
    }

    /**
     * 车间建模树形结构展示
     */
    @GetMapping("/listChildren")
    public AjaxResult listChildren() {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("theDrop", sysShopModelingService.selectChildrenModelingThe());
        return ajax;
    }

    /**
     * 车间建模车间下拉展示
     */
    @GetMapping("/getWorkshop")
    public TableDataInfo getWorkshop() {
        List<SysShopModeling> list = sysShopModelingService.getWorkshop();
        return getDataTable(list);
    }

    /**
     * 车间建模线别下拉展示
     */
    @GetMapping("/getLine")
    public TableDataInfo getLine() {
        List<SysShopModeling> list = sysShopModelingService.getLine();
        return getDataTable(list);
    }

    /**
     * 根据车间id获取线别
     */
    @GetMapping("/getModelingLine/{modelingId}")
    public AjaxResult getModelingLine(@PathVariable("modelingId") long modelingId) {
        return AjaxResult.success(sysShopModelingService.getModelingLine(modelingId));
    }

    /**
     * 根据线别编码获取车间id(fegin调用)
     */
    @GetMapping("/getWorkshopId")
    public AjaxResult getWorkshopId(String lineCode) {
        return AjaxResult.success(sysShopModelingService.getWorkshopId(lineCode));
    }

    /**
     * 根据线别编码获取线别名称
     */
    @GetMapping("/getModelingLineInfo/{lineCode}")
    public AjaxResult getModelingLineInfo(@PathVariable("lineCode") String lineCode) {
        return AjaxResult.success(sysShopModelingService.getModelingLineInfo(lineCode));
    }

    /**
     * 获取分切线别
     */
    @GetMapping("/getCutLine")
    public AjaxResult getCutLine() {
        return AjaxResult.success(sysShopModelingService.getCutLine());
    }


    /**
     * 获取分切线别
     */
    @GetMapping("/getSphinxLine")
    public AjaxResult getSphinxLine() {
        return AjaxResult.success(sysShopModelingService.getSphinxLine());
    }

    /**
     * 获取分切下的车间
     */
    @GetMapping("/getCutShopModeling")
    public AjaxResult getCutShopModeling() {
        return AjaxResult.success(sysShopModelingService.getCutShopModeling());
    }

    /**
     * 根据线别编码获取id
     */
    @GetMapping("/getLineId")
    public Long getLineId(String lineCode) {
        return sysShopModelingService.getLineId(lineCode);
    }

    /**
     * 根据线别编码获取车间编码(fegin调用)
     */
    @GetMapping("/getWorkshopCode")
    public String getWorkshopCode(String lineCode) {
        return sysShopModelingService.getWorkshopCode(lineCode);
    }

    /**
     * 获取脱脂线别
     */
    @GetMapping("/getDegreasLine")
    public AjaxResult getDegreasLine() {
        return AjaxResult.success(sysShopModelingService.getDegreasLine());
    }

    /**
     * 获取分切下的车间
     */
    @GetMapping("/getDegreasShopModeling")
    public AjaxResult getDegreasShopModeling() {
        return AjaxResult.success(sysShopModelingService.getDegreasShopModeling());
    }

    /**
     * 通过车间编码获取绑定线边仓id（Feign）
     */
    @GetMapping("/getStorage")
    public Long getStorage(String lineCode) {
        return sysShopModelingService.getStorage(lineCode);
    }

}
    